import { defineStore } from "pinia";
import { ref } from "vue";
import TencentCloudChat from "@tencentcloud/chat";
import TIMUploadPlugin from "tim-upload-plugin";

 const SDKAppID = 1600094991; // 接入时需要将0替换为您的即时通信 IM 应用的 SDKAppID

  let chat = TencentCloudChat.create({
    SDKAppID,
  });

  chat.setLogLevel(0); // 普通级别，日志量较多，接入时建议使用
  // chat.setLogLevel(1); // release 级别，SDK 输出关键信息，生产环境时建议使用

  // 注册腾讯云即时通信 IM 上传插件
  chat.registerPlugin({ "tim-upload-plugin": TIMUploadPlugin });

export const useChatStore = defineStore("chat", () => {
    //1.chat对象
    let im =ref('')
    im.value = chat

    //2.判断是否登录成功
    let hasImReady = ref(false);
    const onImReady = (value) => {
        hasImReady.value = value;
    }

    //3.获取聊天信息
    const historyChatList = ref([]);
    const mutaHistoryChatList = (value)=>{
        historyChatList.value = value;
    }

    // 4.定义一个函数，处理收到的消息
    const handleReceivedMessage = (message) => {
        historyChatList.value.push(message);
    }


    return {
        im,
        hasImReady,
        onImReady,
        historyChatList,
        mutaHistoryChatList,
        handleReceivedMessage
    }
});
